package com.example.demo.http;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

/**
 * User: wcy
 * Date: 2017/4/8
 * Time: 16:08
 */
public class LoggerThreadLocal {

    private static PropertiesConfiguration config;

    private static final ThreadLocal<ChainNode> currentNode=new ThreadLocal<ChainNode>();

    private static final ThreadLocal<AngelaLoggerProjectNode> zchainProject=new ThreadLocal<AngelaLoggerProjectNode>();

    private static final ThreadLocal<String> nodeId=new ThreadLocal<String>();

    private static final ThreadLocal<String> loggerId = new ThreadLocal<String>();

    private static final ThreadLocal<Long> loggerStartNodeTime = new ThreadLocal<Long>();

    public static void setNodeId(String apiName){
        nodeId.set(apiName);
    }

    public static String getNodeLoggerId() {
        return nodeId.get();
    }

    public static void setLoggerId(String id){
        loggerId.set(id);
    }

    public static String getLoggerId() {
        return loggerId.get();
    }

    public static void setLoggerStartNodeTime(Long currentTime){
        loggerStartNodeTime.set(currentTime);
    }

    public static Long getLoggerStartNodeTime() {
        return loggerStartNodeTime.get();
    }

    public static String getProjectName(){
        return config.getString("zchain.project.name");
    }

    public static String getScenicName(){
        return config.getString("zchain.project.scenic");
    }

    public static void setCurrentNode(ChainNode chainNode){
        currentNode.set(chainNode);
    }

    public static ChainNode getCurrentNode(){
        return currentNode.get();
    }

    public static void setZchainProject(AngelaLoggerProjectNode project){
        zchainProject.set(project);
    }

    public static AngelaLoggerProjectNode getCurrentProject(){
        if(zchainProject.get()==null)
            return new AngelaLoggerProjectNode();
        else
            return zchainProject.get();
    }

    static {
        config = null;
        try {
            config = new PropertiesConfiguration("application.properties");
        } catch (ConfigurationException e) {
            e.printStackTrace();
        }
    }
}